<template>
  <div class="mod-config">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :saveAuthName="saveAuthName"
                :deleteAuthName="deleteAuthName"
                :showAttrs="showAttrs"
    >
      <template v-slot:header>
        <el-button size="small" type="warning" @click="openChartDialog">图表</el-button>
      </template>
    </table-view>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <normal-chart-dialog ref="charDialog"
                         :chartTypes="chartTypes"
                         :chartSearchObj="chartSearchObj"
                         :commitChartSearch="commitChartSearch"
    >
      <template v-slot:chart="{chart}">
        <line-chart v-if="R.equals('line', chart.chartType)" ref="chart"></line-chart>
        <pie-chart v-if="R.equals('pie', chart.chartType)" ref="chart"></pie-chart>
      </template>
    </normal-chart-dialog>
  </div>
</template>

<script>
import AddOrUpdate from './ingredientleave-add-or-update'
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import lineChart from '@/views/charts/ingredient/ingredientLeaveLineChart'
import pieChart from '@/views/charts/ingredient/ingredientLeavePieChart'

export default {
  mixins: [basicMixins],
  data() {
    return {
      chartSearchObj: {
        dataForm: {
          dateTimeRange: []
        },
        config: {
          dateTimeRange: {
            type: 'date',
            clearable: true,
            dateType: 'daterange',
            label: '时间范围'
          }
        }
      },
      chartTypes: [
        {label: 'pie', text: '饼状图'},
        {label: 'line', text: '折线图'}
      ],
      searchAttrs: {
        ingredientInfoId: {
          type: 'autoComplete',
          placeholder: '辅料名称',
          querySearchApiName: 'ingredientApi/getIngredientInfoList'
        },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        }
      },
      primaryKey: 'id',
      listApiName: 'ingredientApi/listIngredientLeave',
      deleteApiName: 'ingredientApi/deleteIngredientLeave',
      saveAuthName: 'ingredient:ingredientleave:save',
      deleteAuthName: 'ingredient:ingredientleave:delete',
      showAttrs: {
        ingredientInfoName: {
          label: '辅料名称'
        },
        tunnage: {
          label: '吨数'
        },
        dayTime: {
          label: '日期', type: 'date'
        },
        status: {
          label: '状态',
          type: 'radio',
          items: [
            {value: 0, text: '禁用', tagType: 'danger'},
            {value: 1, text: '正常'}
          ]
        }
      }
    }
  },
  components: {
    AddOrUpdate,
    tableView,
    lineChart,
    pieChart
  }
}
</script>
